package com.cxyd.service;

import com.cxyd.common.utils.ApiResult;
import com.cxyd.modules.api.dto.RcsResult;
import com.cxyd.modules.job.task.scanTask.AnalyzeTask;
import com.cxyd.modules.job.task.scanTask.PostRcsTask;
import com.cxyd.modules.wcs.dto.*;
import com.cxyd.modules.wcs.entity.RouteCtuEntity;
import com.cxyd.modules.wcs.service.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ReceiveTaskTestService {
    @Autowired
    private ReceiveTaskService receiveTaskService;
    @Autowired
    private PostRcsTask rcsTask;
    @Resource
    private PostWmsService postWmsService;
    @Autowired
    private AgvCallbackService callbackService;
    @Autowired
    private AgvTrkService agvTrkService;
    @Autowired
    private AnalyzeTask analyzeTask;
    @Resource
    private TrkService trkService;
    @Resource
    private PlcItemService itemService;
    @Resource
    private RouteCtuService ctuService;

    @Test
    public void analyzeTest() {
        ReceiveTaskDTO dto = new ReceiveTaskDTO();
        dto.setRequestPk("ae02989db5d749818ebb6eb849657299");
        dto.setContNo("B00603");
        dto.setContType("2");
        dto.setFrmPos("900003FJ501013");
        dto.setToPos("200003D7507011");
        dto.setTrkType("IN");
        dto.setReqTime("2024-10-04 16:44:00");
        receiveTaskService.analyzeHandler(dto);
    }

    @Test
    public void postRcsTest() {
        AgvTrkJobDTO record = agvTrkService.getOneRecord("CV01");
        System.out.println("result:" + record);
    }

    @Test
    public void callbackHandle() {
        AgvCallbackDTO dto = new AgvCallbackDTO();
        dto.setReqCode("1541954B96B1112");
        dto.setTaskCode("90b4569c94be452c95dc7464a714592b");
        dto.setReqTime("2024-09-03 10:08:06");
        dto.setCurrentPositionCode("CV01");
        dto.setMapCode("F01");
        dto.setMethod("start");
        dto.setRobotCode("6001");

        RcsResult result = callbackService.callbackHandle(dto);
        System.out.println("result:" + result);
    }

    @Test
    public void agvTrkHandleTest() {
        RcsResult response = new RcsResult().success("1723953037918");
        AgvTrkDTO dto = new AgvTrkDTO();
        dto.setCtnrCode("60002");
//        agvTrkService.agvTrkHandle(dto, response);
    }

    @Test
    public void scanAgvTrkTest() {
        analyzeTask.scanTask();
    }

    @Test
    public void updateTrkByContNoTest() {
        trkService.updateTrkByContNo("60003");
    }

    @Test
    public void postWmsHandleTest() {
        PostWmsDTO dto = new PostWmsDTO();
        dto.setContNo("600001");
        dto.setRequestPk("c4390882cafd4c49a3d46f2754d1d725");
        dto.setPostSt(0);
        dto.setNoticeType("2");
        dto.setCurPos("HW-01K010201");
        dto.setCode("0");
        dto.setResult("success");

        ApiResult response = new ApiResult().success("success");
        postWmsService.postWmsHandle(dto, response);
    }

    @Test
    public void signalJudgeTest() {
        boolean flag = itemService.signalJudge("60001", "GET", "900001FJ501013");
    }

    @Test
    public void getTaskTypByConditionTest() {
        RouteCtuEntity in = ctuService.getTaskTypByCondition("IN", "900003FJ501013", "200005D7507012");
        System.out.println("result" + in);
    }
}
